class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        ListNode* newlist = new ListNode(0);
        ListNode* p = newlist;
        int flag = 0;
        while(l1 || l2 || flag !=0)
        {
            int l1val = l1 ? l1->val : 0;
            int l2val = l2 ? l2->val : 0;
            int sum = l1val+l2val +flag;
            flag = sum/10; //小于10结果是0 大于10那么结果一定是1
            ListNode* newnode = new ListNode;
            newnode->val = sum%10;
            newnode->next = NULL;
            p->next = newnode;
            p = p->next;
            if(l1) l1 = l1->next;
            if(l2) l2 = l2->next;
        }
        return newlist->next;
    }